package org.arkeologgr.appening.parser;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.net.UrlQuerySanitizer;
import android.util.Log;

public class BaseParser {

	private static final String TAG = "BaseParser";
	private String jsonString = "";
	
	private String domainUrl = "http://sirius066.homelinux.com:8180/arkeologgr/services";

	public BaseParser()  {



	}

	protected void init(String url) throws Exception{
		Log.d(TAG, "init called");
		Log.d(TAG, "url=" + url);
		try {
			
			
			HttpClient client = new DefaultHttpClient();
			HttpGet get = new HttpGet(new URI(url));

			HttpResponse rp = client.execute(get);

			if (rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				jsonString = EntityUtils.toString(rp.getEntity(), "UTF-8");
			} else {
				Log.e(TAG, "init failed - error statusCode for URL: " + url + " statusCode=" + rp.getStatusLine().getStatusCode());
				throw new Exception("Error connection to http: statusCode=" + rp.getStatusLine().getStatusCode());
			}

		}  catch (Exception e) {
			Log.e(TAG, "getJsonString failed - Invalid URL: " + url, e);
			throw new Exception("Error connection to http ", e);
		}

	}

	public String getJsonString() {
		return jsonString;
	}

	public String getDomainUrl() {
		return domainUrl;
	}



}
